home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 2 / adb / a-tideau < prev    next >
Text File  |  1996-02-12  |  8KB  |  263 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --              A D A . T E X T _ I O . D E C I M A L _ A U X               --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.10 $                             --
  10. --                                                                          --
  11. --     Copyright (C) 1992,1993,1994,1995 Free Software Foundation, Inc.     --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with Ada.Text_IO.Generic_Aux; use Ada.Text_IO.Generic_Aux;
  37. with Ada.Text_IO.Float_Aux;   use Ada.Text_IO.Float_Aux;
  38.  
  39. with System.Img_Dec; use System.Img_Dec;
  40. with System.Img_LLD; use System.Img_LLD;
  41. with System.Val_Dec; use System.Val_Dec;
  42. with System.Val_LLD; use System.Val_LLD;
  43.  
  44. package body Ada.Text_IO.Decimal_Aux is
  45.  
  46.    -------------
  47.    -- Get_Dec --
  48.    -------------
  49.  
  50.    function Get_Dec
  51.      (File   : in File_Type;
  52.       Width  : in Field;
  53.       Scale  : Integer)
  54.       return   Integer
  55.    is
  56.       Buf  : String (1 .. Field'Last);
  57.       Ptr  : aliased Integer := 0;
  58.       Stop : Integer := 0;
  59.       Item : Integer;
  60.  
  61.    begin
  62.       if Width /= 0 then
  63.          Load_Width (File, Width, Buf, Stop);
  64.          String_Skip (Buf, Ptr);
  65.       else
  66.          Load_Real (File, Buf, Stop);
  67.       end if;
  68.  
  69.       Item := Scan_Decimal (Buf, Ptr'Access, Stop, Scale);
  70.       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
  71.       return Item;
  72.    end Get_Dec;
  73.  
  74.    -------------
  75.    -- Get_LLD --
  76.    -------------
  77.  
  78.    function Get_LLD
  79.      (File   : in File_Type;
  80.       Width  : in Field;
  81.       Scale  : Integer)
  82.       return   Long_Long_Integer
  83.    is
  84.       Buf  : String (1 .. Field'Last);
  85.       Ptr  : aliased Integer := 0;
  86.       Stop : Integer := 0;
  87.       Item : Long_Long_Integer;
  88.  
  89.    begin
  90.       if Width /= 0 then
  91.          Load_Width (File, Width, Buf, Stop);
  92.          String_Skip (Buf, Ptr);
  93.       else
  94.          Load_Real (File, Buf, Stop);
  95.       end if;
  96.  
  97.       Item := Scan_Long_Long_Decimal (Buf, Ptr'Access, Stop, Scale);
  98.       Check_End_Of_Field (File, Buf, Stop, Ptr, Width);
  99.       return Item;
  100.    end Get_LLD;
  101.  
  102.    -------------
  103.    -- Put_Dec --
  104.    -------------
  105.  
  106.    procedure Put_Dec
  107.      (File  : in File_Type;
  108.       Item  : in Integer;
  109.       Fore  : in Field;
  110.       Aft   : in Field;
  111.       Exp   : in Field;
  112.       Scale : Integer)
  113.    is
  114.       Buf : String (1 .. Field'Last);
  115.       Ptr : Natural := 0;
  116.  
  117.    begin
  118.       Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
  119.       Put_Item (File, Buf (1 .. Ptr));
  120.    end Put_Dec;
  121.  
  122.    -------------
  123.    -- Put_LLD --
  124.    -------------
  125.  
  126.    procedure Put_LLD
  127.      (File  : in File_Type;
  128.       Item  : in Long_Long_Integer;
  129.       Fore  : in Field;
  130.       Aft   : in Field;
  131.       Exp   : in Field;
  132.       Scale : Integer)
  133.    is
  134.       Buf : String (1 .. Field'Last);
  135.       Ptr : Natural := 0;
  136.  
  137.    begin
  138.       Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
  139.       Put_Item (File, Buf (1 .. Ptr));
  140.    end Put_LLD;
  141.  
  142.    --------------
  143.    -- Gets_Dec --
  144.    --------------
  145.  
  146.    function Gets_Dec
  147.      (From  : in String;
  148.       Last  : access Positive;
  149.       Scale : Integer)
  150.       return  Integer
  151.    is
  152.       Pos  : aliased Integer;
  153.       Item : Integer;
  154.  
  155.    begin
  156.       String_Skip (From, Pos);
  157.       Item := Scan_Decimal (From, Pos'Access, From'Last, Scale);
  158.       Last.all := Pos - 1;
  159.       return Item;
  160.  
  161.    exception
  162.       when Constraint_Error =>
  163.          Last.all := Pos - 1;
  164.          raise Data_Error;
  165.    end Gets_Dec;
  166.  
  167.    --------------
  168.    -- Gets_LLD --
  169.    --------------
  170.  
  171.    function Gets_LLD
  172.      (From  : in String;
  173.       Last  : access Positive;
  174.       Scale : Integer)
  175.       return  Long_Long_Integer
  176.    is
  177.       Pos  : aliased Integer := From'First;
  178.       Item : Long_Long_Integer;
  179.  
  180.    begin
  181.       String_Skip (From, Pos);
  182.       Item := Scan_Long_Long_Decimal (From, Pos'Access, From'Last, Scale);
  183.       Last.all := Pos - 1;
  184.       return Item;
  185.  
  186.    exception
  187.       when Constraint_Error =>
  188.          Last.all := Pos - 1;
  189.          raise Data_Error;
  190.    end Gets_LLD;
  191.  
  192.    --------------
  193.    -- Puts_Dec --
  194.    --------------
  195.  
  196.    procedure Puts_Dec
  197.      (To    : out String;
  198.       Item  : in Integer;
  199.       Aft   : in Field;
  200.       Exp   : in Field;
  201.       Scale : Integer)
  202.    is
  203.       Buf  : String (1 .. Field'Last);
  204.       Fore : Integer;
  205.       Ptr  : Natural := 0;
  206.  
  207.    begin
  208.       if Exp = 0 then
  209.          Fore := To'Length - 1 - Aft;
  210.       else
  211.          Fore := To'Length - 2 - Aft - Exp;
  212.       end if;
  213.  
  214.       if Fore < 1 then
  215.          raise Layout_Error;
  216.       end if;
  217.  
  218.       Set_Image_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
  219.  
  220.       if Ptr > To'Length then
  221.          raise Layout_Error;
  222.       else
  223.          To := Buf (1 .. Ptr);
  224.       end if;
  225.    end Puts_Dec;
  226.  
  227.    --------------
  228.    -- Puts_Dec --
  229.    --------------
  230.  
  231.    procedure Puts_LLD
  232.      (To    : out String;
  233.       Item  : in Long_Long_Integer;
  234.       Aft   : in Field;
  235.       Exp   : in Field;
  236.       Scale : Integer)
  237.    is
  238.       Buf  : String (1 .. Field'Last);
  239.       Fore : Integer;
  240.       Ptr  : Natural := 0;
  241.  
  242.    begin
  243.       if Exp = 0 then
  244.          Fore := To'Length - 1 - Aft;
  245.       else
  246.          Fore := To'Length - 2 - Aft - Exp;
  247.       end if;
  248.  
  249.       if Fore < 1 then
  250.          raise Layout_Error;
  251.       end if;
  252.  
  253.       Set_Image_Long_Long_Decimal (Item, Buf, Ptr, Scale, Fore, Aft, Exp);
  254.  
  255.       if Ptr > To'Length then
  256.          raise Layout_Error;
  257.       else
  258.          To := Buf (1 .. Ptr);
  259.       end if;
  260.    end Puts_LLD;
  261.  
  262. end Ada.Text_IO.Decimal_Aux;
  263.